﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AcctrueWMS.Foundation.WebControls
{
    public class AccTextBox : AccControl
    {
        public override string Render()
        {
            StringBuilder sb = new StringBuilder();
            #region 生成控件
            // sb.Append(GenerateDescription());
            sb.Append("<nobr>");

            sb.Append("<input type='text' class=\"TextBoxCommon\" ");
            sb.Append(GenerateBasicProperty());
            sb.Append(" value='" + GetControlValue() + "' ");
            if (!string.IsNullOrEmpty(this.ValidExpression))
            {
                //sb.AppendFormat(" validpattern='{0}' ", this.ValidExpression);
                sb.AppendFormat(@" validpattern='{0}' onblur='wmsCommon.dataValideByRegular(this)' tip='{1}' ", this.ValidExpression, Tip);
            }
            else
            {
                if (!string.IsNullOrEmpty(this.DataType))
                {
                    if (Context.RenderMode == 1)//新增 注册正则验证
                    {
                        switch (this.DataType)
                        {
                            case "Int32": sb.AppendFormat(@" validpattern='{0}' onblur='wmsCommon.dataTypeValide(this)' tip='{1}' ", string.IsNullOrEmpty(this.ValidExpression) == true ? "^-?\\d+$" : this.ValidExpression, Tip); break;//Int  
                            case "Int": sb.AppendFormat(@" validpattern='^-?\d+$' onblur='wmsCommon.dataTypeValide(this)' ", string.IsNullOrEmpty(this.ValidExpression) == true ? "^-?\\d+$" : this.ValidExpression, Tip); break;
                            case "Decimal": sb.AppendFormat(@" validpattern='^-?\d+(\.\d+)?$' onblur='wmsCommon.dataTypeValide(this)' ", string.IsNullOrEmpty(this.ValidExpression) == true ? "^-?\\d+$" : this.ValidExpression, Tip); break;
                            case "Float": sb.AppendFormat(@" validpattern='^-?\d+(\.\d+)?$' onblur='wmsCommon.dataTypeValide(this)' ", string.IsNullOrEmpty(this.ValidExpression) == true ? "^-?\\d+$" : this.ValidExpression, Tip); break;
                        }
                    }
                    else if (Context.RenderMode == 2)//修改 注册正则验证
                    {
                        switch (this.DataType)
                        {
                            case "Int32": sb.AppendFormat(@" validpattern='^-?\d+$' onchange='wmsCommon.dataTypeValide(this)' ", this.ValidExpression); break;//Int  
                            case "Int": sb.AppendFormat(@" validpattern='^-?\d+$' onchange='wmsCommon.dataTypeValide(this)' ", this.ValidExpression); break;
                            case "Decimal": sb.AppendFormat(@" validpattern='^-?\d+(\.\d+)?$' onchange='wmsCommon.dataTypeValide(this)' ", this.ValidExpression); break;
                            case "Float": sb.AppendFormat(@" validpattern='^-?\d+(\.\d+)?$' onchange='wmsCommon.dataTypeValide(this)' ", this.ValidExpression); break;
                        }
                    }
                }
            }

            if (this.Musted)
            {
                Style = "font-size:	9pt;width:90%;height:20px;border:1px solid #7b9ebd;";
                if (!string.IsNullOrEmpty(Style))
                    sb.Append(string.Format("style=\"{0}\"", Style));
                sb.Append(" >");
                sb.Append("</input>");
                sb.Append("<font style='color:red'>*</font>");
            }
            else
            {
                Style = "font-size:	9pt;width:90%;height:20px;border:1px solid #7b9ebd;";
                if (!string.IsNullOrEmpty(Style))
                    sb.Append(string.Format("style=\"{0}\"", Style));
                sb.Append(" >");
                sb.Append("</input>");
            }
            sb.Append("</nobr>");
            #endregion

            #region 生成脚本
            #endregion
            return sb.ToString();
        }
    }
}
